import java.util.HashMap;

/**
 * 
 */

/**
 * @author zhongfang
 *
 */
public class ContainsDuplicateIII {

	public static boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
		HashMap<Integer,Integer> hm=new HashMap();
        for(int i=0;i<nums.length;i++){
            for(int j=0;j<=t;j++){
                if(hm.containsKey(nums[i]+j)){
                    if(i-(Integer)hm.get(nums[i]+j)<=k){//check index
                        return true;
                    }
                }else if(hm.containsKey(nums[i]-j)){
                    if(i-(Integer)hm.get(nums[i]-j)<=k){//check index
                        return true;
                    }
                }
            }
            hm.put(nums[i],i);
        }
        return false;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println(containsNearbyAlmostDuplicate(new int[]{0,2147483647},1,2147483647));
	}

}
